﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyAttackState : IEnemyState
{
    public EnemyAttackState(EnemyFSMSystem fsm, Character character) : base(fsm, character)
    {
    }

    public override void Act(List<Character> targets)
    {
        if(targets!=null && targets.Count > 0)
        {
            m_character.Attack(targets[0]);
        }
    }

    public override void Reason(List<Character> targets)
    {
        if (targets == null || targets.Count == 0)
        {
            m_fsm.PerformTransition(EnemyTransition.LostSoldier);
            return;
        }
        float distance = Vector3.Distance(targets[0].Position, m_character.Position);
        if (distance > m_character.AttackRange)
        {
            m_fsm.PerformTransition(EnemyTransition.LostSoldier);
            return;
        }
    }
}
